<template>
  <header>
    <!-- 顶部导航条 -->
    <div class="top-bar">
      <div class="container">
        <div class="left">
          <span>质量公告</span>
          <span>医疗器械质量公告</span>
        </div>
        <div class="right">
          <template v-if="isLoggedIn">
            <span>欢迎，{{ currentUser.username }}</span>
            <a href="#" @click.prevent="handleLogout">退出</a>
          </template>
          <template v-else>
            <router-link to="/login">登录</router-link>
            <router-link to="/register">注册</router-link>
          </template>
          <a href="#">帮助中心</a>
          <a href="#" class="download">
            <i class="phone-icon"></i>
            下载 APP
          </a>
          <a href="#">资质证照 / 协议规则</a>
        </div>
      </div>
    </div>

    <!-- 主导航栏 -->
    <div class="main-nav">
      <div class="container">
        <div class="logo">
          <a href="/">小米有品</a>
        </div>
        <div class="search-box">
          <input type="text" placeholder="电视">
          <button class="search-btn">
            <i class="search-icon"></i>
          </button>
        </div>
        <div class="cart">
          <i class="cart-icon"></i>
        </div>
      </div>
    </div>
  </header>
</template>

<script>
export default {
  data() {
    return {
      currentUser: null
    }
  },
  computed: {
    isLoggedIn() {
      return this.currentUser !== null
    }
  },
  created() {
    // 检查本地存储中的用户信息
    const userStr = localStorage.getItem('currentUser')
    if (userStr) {
      this.currentUser = JSON.parse(userStr)
    }
  },
  methods: {
    handleLogout() {
      localStorage.removeItem('currentUser')
      this.currentUser = null
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
header {
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.top-bar {
  background: #333;
  color: #b0b0b0;
  height: 40px;
  line-height: 40px;
  font-size: 12px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.left span {
  margin-right: 20px;
  cursor: pointer;
}

.right {
  display: flex;
  gap: 20px;
}

.right a {
  color: #b0b0b0;
  text-decoration: none;
}

.right a:hover {
  color: #fff;
}

.download {
  display: flex;
  align-items: center;
  gap: 5px;
}

.phone-icon::before {
  content: "📱";
}

.main-nav {
  height: 100px;
  background: #fff;
}

.main-nav .container {
  height: 100%;
}

.logo {
  font-size: 28px;
}

.logo a {
  color: #826c5b;
  text-decoration: none;
  font-weight: bold;
}

.search-box {
  display: flex;
  align-items: center;
  width: 400px;
}

input {
  flex: 1;
  height: 40px;
  padding: 0 15px;
  border: 1px solid #e0e0e0;
  border-right: none;
  outline: none;
}

.search-btn {
  width: 50px;
  height: 40px;
  border: none;
  background: #826c5b;
  color: #fff;
  cursor: pointer;
}

.search-icon::before {
  content: "🔍";
}

.cart {
  font-size: 24px;
  cursor: pointer;
}

.cart-icon::before {
  content: "🛒";
}
</style> 